//初始化
mui.init();
var mask = mui.createMask(); //遮罩层
//获取本地储存数据
var my_phone = localStorage.getItem("my_phone");
var user_id = localStorage.getItem("user_id");
var is_realname, pay_password, description;
var status = 0; //修改手机号审核状态
//返回user页面
$(document).on('tap', '.go_user', function() {
	window.top.location.href = "../my/my_user.html";
})
//明细
//document.getElementById("advance_payment_detail").addEventListener("tap", function() {
//	mui.openWindow({
//		url: '../my/bank_record.html',
//		createNew: true
//	})
//});
//添加银行卡
document.getElementById("bank_card_add").addEventListener("tap", function() {
	mui.openWindow({
		url: '../my/add_bank_card.html',
		createNew: true
	})
});

//modify_bank_card
mui("body").on("tap", ".money_center_bank", function() {
	plus.nativeUI.showWaiting("加载中...");
	mask.show(); //显示遮罩层
	var commodity_id = $(this).attr("commodity_id");
	//alert(commodity_id)
	mui.openWindow({
		url: "../my/modify_bank_card.html",
		id: "modify_bank_card",
		extras: {
			commodity_id: commodity_id
		},
		createNew: true,
		waiting: {
			autoShow: false
		}
	}, mask.close());
});

//userinfo接口调用
function userinfo() {
	mui.ajax(user_url + '/api/user/getUserBank', {
		dataType: 'json', //服务器返回json格式数据
		type: 'post', //HTTP请求类型
		timeout: 10000, //超时时间设置为10秒；
		success: function(data) {
			console.log(JSON.stringify(data))
			
			if(data.code == 10000) {
				var html = ""
				var listData = data.resp;
				if(listData!=null || listData!=''){
					for(var i = 0; i < listData.length; i++) {						
						html += '<div class="money_center_bank" commodity_id=' + listData[i].id + '>'
						html += '<div class="center_bank_name">'
						html += '<div style="padding:6px;"></div>'
						html += '<div class="center_bank_con">'
						html += '<p>'+listData[i].bank_name.split('-')[0]+'</p>'
						html += '<p style="padding-top: 10px; margin-bottom: -10px;">收款姓名:<span style="font-size: 14px;">'+listData[i].name+'</span></p>'
						html += '</div>'
						html += '</div>'
						html += '<div class="center_bank_name">'
						html += '<div></div>'
						html += '<div class="center_bank_con">'
						html += '<span>***</span>'
						html += '<span>***</span>'
						html += '<span>***</span>'
						html += '<span>'+listData[i].card_no.substr(-4)+'</span>'
						html += '</div>'
						html += '</div>'
						html += '</div>';
					}
					$(".bank-list").html(html);
				}				
			}
			else{
				mui.alert(data.msg);
			}
		},
		error: function(xhr, type, errorThrown) { //异常处理；
			console.log(type);
		}
	});

}

//页面进入执行方法
window.onload = function() {
	mui.plusReady(function() {
//		self = plus.webview.currentWebview();
		userinfo(); //用户接口方法
		plus.nativeUI.closeWaiting(); //关闭等待
		mask.close(); //关闭遮罩层
		//页面刷新
		window.addEventListener('refresh_method', function(e) { //执行刷新
			location.reload();
		});
	});
}